home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / Vertest / Source / Vertest.c
Encoding:
C/C++ Source or Header  |  1996-09-17  |  10.7 KB  |  417 lines  |  [TEXT/CWIE]

  1. /*______________________________________________________*/
  2. /*                            C Shell                        */
  3. /*                          by                          */
  4. /*                  RICHARD P. COLLYER                  */
  5. /*                       09/02/87                       */
  6. /*______________________________________________________*/
  7.  
  8. #include    <CType.h>
  9. #include    <Quickdraw.h>
  10. #include    <Windows.h>
  11. #include    <OSUtils.h>
  12. #include    <Controls.h>
  13. #include    <desk.h>
  14. #include    <dialogs.h>
  15. #include    <Events.h>
  16. #include    <Files.h>
  17. #include     <Fonts.h>
  18. #include    <Memory.h>
  19. #include    <Menus.h>
  20. #include    <Notification.h>
  21. #include    <OSEvents.h>
  22. #include    <Packages.h>
  23. #include    <Palettes.h>
  24. #include     <Processes.h>
  25. #include    <Resources.h>
  26. //#include    <SANE.h>
  27. #include    <SegLoad.h>
  28. #include    <Sound.h>
  29. #include    <String.h>
  30. #include    <ToolUtils.h>
  31. #include    <StdIO.h>
  32. #include    <math.h>
  33. #include    <TextUtils.h>
  34.  
  35. extern _DataInit();
  36.  
  37. #define    TRUE            0xFF
  38. #define    FALSE            0
  39. #define    VERSION            1
  40. #define    SR_BIT            0
  41.  
  42. #define    appleID            128            
  43. #define    appleMenu        0
  44. #define    aboutMeCommand    1
  45.  
  46. #define    fileID            129
  47. #define    startCommand    1
  48. #define    quitCommand     2
  49.  
  50. #define    editID            130
  51.  
  52. #define    aboutMeDLOG        128
  53. #define    okButton        1
  54. #define    authorItem        2
  55. #define    languageItem    3
  56.  
  57. #define    nocolorID        130
  58. #define    no68020            133
  59. #define    no68881            132
  60. #define    no256            134
  61. #define    nosys6            135
  62.  
  63. long                Tick;
  64. int                    yieldTime, err, numcolor, offLeft, offTop, offRight, offBottom;
  65. Rect                screenRect, BaseRect, TotalRect, minRect;
  66. WindowPtr            whichWindow, myWindow;
  67. CTabHandle            mycolors;
  68. PaletteHandle        srcPalette;
  69. MenuHandle            mymenu1, mymenu2, mymenu0;
  70. EventRecord         myEvent;
  71. Boolean                DoneFlag;
  72. GDHandle            theGDevice;
  73. SysEnvRec            theWorld;
  74. OSErr                OSys;
  75.  
  76. void start(void);
  77. void showAboutMeDialog(void);
  78. void init(void);
  79. void doCommand(long mResult);
  80.  
  81. /*______________________________________________________*/
  82. /*                What ever You want                    */
  83. /*______________________________________________________*/
  84. void start()
  85. {
  86.  
  87.     VersRecHndl version;
  88.     StringPtr messagePtr;
  89.     Str255 longMessage, countsstrPtr;
  90.     //char *countsstrPtr, countstr;
  91.     
  92.     //countsstrPtr = &countstr;
  93.  
  94.     version = (VersRecHndl) GetResource ('vers', 1);
  95.     
  96.     messagePtr = (StringPtr) (((unsigned long) &(**version).shortVersion[1]) + 
  97.             ((**version).shortVersion[0]));
  98.  
  99.     BlockMove((Ptr) messagePtr, &longMessage, ((unsigned char) *messagePtr) + 1);
  100.  
  101. //short version
  102.     MoveTo(10,10);
  103.     DrawString((**version).shortVersion);
  104. //long version
  105.     MoveTo(10,30);
  106.     DrawString(longMessage);
  107. //country code
  108.     MoveTo(10,50);
  109.     NumToString((**version).countryCode,countsstrPtr);
  110.     DrawString(countsstrPtr);
  111. //major rev
  112.     MoveTo(10,70);
  113.     NumToString((**version).numericVersion.majorRev,countsstrPtr);
  114.     DrawString(countsstrPtr);
  115. // minorAndBugRev
  116.     MoveTo(10,90);
  117.     NumToString((**version).numericVersion.minorAndBugRev,countsstrPtr);
  118.     DrawString(countsstrPtr);
  119. //stage
  120.     MoveTo(10,110);
  121.     NumToString((**version).numericVersion.stage,countsstrPtr);
  122.     DrawString(countsstrPtr);
  123. // non rel rev
  124.     MoveTo(10,130);
  125.     NumToString((**version).numericVersion.nonRelRev,countsstrPtr);
  126.     DrawString(countsstrPtr);
  127.     
  128.     return;
  129. }
  130.  
  131. /*______________________________________________________*/
  132. /*                 About Prog Dialog                    */
  133. /*______________________________________________________*/
  134. void showAboutMeDialog()
  135. {
  136.     GrafPtr     savePort;
  137.     DialogPtr    theDialog;
  138.     short        itemHit;
  139.  
  140.     GetPort(&savePort);
  141.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  142.     SetPort(theDialog);
  143.  
  144.     do {
  145.         ModalDialog(nil, &itemHit);
  146.     } while (itemHit != okButton);
  147.  
  148.     CloseDialog(theDialog);
  149.  
  150.     SetPort(savePort);
  151.     return;
  152. }
  153.  
  154. /*______________________________________________________*/
  155. /*                 Do Menu Function                     */
  156. /*______________________________________________________*/
  157. void doCommand(mResult)
  158.     long    mResult;
  159. {
  160.     int                     theMenu, theItem;
  161.     char                    daName[256];
  162.     GrafPtr                 savePort;
  163.  
  164.     theItem = LoWord(mResult);
  165.     theMenu = HiWord(mResult);
  166.     
  167.     switch (theMenu) {
  168. /*______________________________________________________*/
  169. /*                    Do Apple Menu                     */
  170. /*______________________________________________________*/
  171.         case appleID:
  172.             if (theItem == aboutMeCommand)
  173.                 showAboutMeDialog();
  174.             else {
  175.                 GetMenuItemText(mymenu0, theItem, (unsigned char*)daName);
  176.                 GetPort(&savePort);
  177.                 (void) OpenDeskAcc((unsigned char*)daName);
  178.                 SetPort(savePort);
  179.             }
  180.             break;
  181. /*______________________________________________________*/
  182. /*                     Do File Menu                     */
  183. /*______________________________________________________*/
  184.         case fileID:
  185.             switch (theItem) {
  186.                 case startCommand:
  187.                     start();
  188.                     break;
  189.                 case quitCommand:
  190.                     DoneFlag = TRUE;
  191.                     break;
  192.                 default:
  193.                     break;
  194.                 }
  195.             break;
  196. /*______________________________________________________*/
  197. /*                     Do Edit Menu                     */
  198. /*______________________________________________________*/
  199.         case editID:
  200.             switch (theItem) {
  201.                 default:
  202.                     break;
  203.                 }
  204.             break;
  205.         default:
  206.             break;
  207.         }
  208.     HiliteMenu(0);
  209.     return;
  210. }
  211.  
  212.  
  213. /*______________________________________________________*/
  214. /*               Initialization traps                   */
  215. /*______________________________________________________*/
  216. void init()
  217. {
  218.     RgnHandle        tempRgn;
  219.     
  220.     //commented out UnloadSeg for MetroWerks compiler
  221.     //UnloadSeg(_DataInit);
  222.     InitGraf(&qd.thePort);
  223.     FlushEvents(everyEvent, 0);
  224.     InitWindows();
  225.     InitDialogs(nil);
  226.     InitCursor();
  227. /*______________________________________________________*/
  228. /*            If not right Machine then stop            */
  229. /*______________________________________________________*/
  230.     OSys = SysEnvirons(VERSION,&theWorld);
  231.     /*if(!theWorld.hasColorQD) {
  232.         crashDia = GetNewDialog (nocolorID, nil, (WindowPtr) -1);
  233.         DrawDialog (crashDia);
  234.         Delay (300, tick);
  235.         ExitToShell();
  236.         }
  237.     if(theWorld.processor != env68020) {
  238.         crashDia = GetNewDialog (no68020, nil, (WindowPtr) -1);
  239.         DrawDialog (crashDia);
  240.         Delay (300, tick);
  241.         ExitToShell();
  242.         }
  243.     if(!theWorld.hasFPU) {
  244.         crashDia = GetNewDialog (no68881, nil, (WindowPtr) -1);
  245.         DrawDialog (crashDia);
  246.         Delay (300, tick);
  247.         ExitToShell();
  248.         }
  249.     if(theWorld.systemVersion < 0x0600) {
  250.         crashDia = GetNewDialog (nosys6, nil, (WindowPtr) -1);
  251.         DrawDialog (crashDia);
  252.         Delay (300, tick);
  253.         ExitToShell();
  254.         }*/
  255.             
  256. /*______________________________________________________*/
  257. /*                     Set Rects                        */
  258. /*______________________________________________________*/
  259.     screenRect = qd.screenBits.bounds;
  260.     offLeft = 0;
  261.     offTop = 0;
  262.     offRight = screenRect.right;
  263.     offBottom = screenRect.bottom;
  264.     SetRect(&BaseRect, 40, 60, 472, 282);
  265.     tempRgn = GetGrayRgn();
  266.     HLock ((Handle) tempRgn);
  267.     TotalRect = (**tempRgn).rgnBBox;
  268.     SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40, 
  269.                 (**tempRgn).rgnBBox.bottom - 40);
  270.     HUnlock ((Handle) tempRgn);
  271.  
  272. /*______________________________________________________*/
  273. /*        Open Window & set Palette & Picture           */
  274. /*______________________________________________________*/
  275.     theGDevice = GetMainDevice();
  276.     HLock ((Handle) theGDevice);
  277.     mycolors = (**(**theGDevice).gdPMap).pmTable;
  278.     numcolor = (**(**theGDevice).gdPMap).pixelSize;
  279.     HUnlock((Handle) theGDevice);
  280.     switch (numcolor) {
  281.         case 1:
  282.             numcolor = 2;
  283.             break;
  284.         case 2:
  285.             numcolor = 4;
  286.             break;
  287.         case 4:
  288.             numcolor = 16;
  289.             break;
  290.         case 8:
  291.             numcolor = 256;
  292.             break;
  293.         }
  294.     
  295.     myWindow = NewCWindow(nil, &BaseRect, (ConstStr255Param)"", TRUE, zoomDocProc, 
  296.                             (WindowPtr) -1, TRUE, 150);
  297.     SetPort((WindowPtr) myWindow);
  298.     DrawGrowIcon (myWindow);
  299.  
  300.     srcPalette = NewPalette (numcolor, mycolors, pmCourteous, 0);
  301.     SetPalette ((WindowPtr) myWindow, srcPalette, TRUE);
  302.     
  303. /*______________________________________________________*/
  304. /*                    Set menus                         */
  305. /*______________________________________________________*/
  306.     mymenu0 = GetMenu(appleID);
  307.     AppendResMenu(mymenu0, 'DRVR');
  308.     InsertMenu(mymenu0,0);
  309.     mymenu1 = NewMenu(129,(ConstStr255Param)"\pFile");
  310.     AppendMenu(mymenu1,(ConstStr255Param)"\pStart");
  311.     AppendMenu(mymenu1,(ConstStr255Param)"\pQuit");
  312.     InsertMenu(mymenu1,0);
  313.     mymenu2 = NewMenu(130,(ConstStr255Param)"\pEdit");
  314.     InsertMenu(mymenu2,0);
  315.     DrawMenuBar();
  316.  
  317. /*______________________________________________________*/
  318. /*                  Init variables                      */
  319. /*______________________________________________________*/
  320.     DoneFlag = FALSE;
  321.     yieldTime = 0;
  322.     return;
  323. }
  324.  
  325. void main(void)
  326. {
  327.     Boolean        track;
  328.     long        growResult;
  329. /*______________________________________________________*/
  330. /*                   Main Event loop                    */
  331. /*______________________________________________________*/
  332.     init();
  333.     for ( ;; ) {
  334.         if (DoneFlag) {
  335.             ExitToShell();
  336.             }
  337.         if (WaitNextEvent(everyEvent, &myEvent, yieldTime, nil)) {
  338.             switch (myEvent.what) {
  339.                 case mouseDown:
  340.                     switch (FindWindow(myEvent.where, &whichWindow)) {
  341.                         case inSysWindow:
  342.                             SystemClick(&myEvent, whichWindow);
  343.                             break;
  344.                         case inMenuBar:
  345.                             doCommand(MenuSelect(myEvent.where));
  346.                             break;
  347.                         case inContent:
  348.                             break;
  349.                         case inDrag:
  350.                             DragWindow (whichWindow, myEvent.where, &TotalRect);
  351.                             EraseRect (&whichWindow->portRect);
  352.                             DrawGrowIcon (whichWindow);
  353.                             break;
  354.                         case inGrow:
  355.                             growResult = GrowWindow (whichWindow, myEvent.where,
  356.                                                     &minRect);
  357.                             SizeWindow(whichWindow, LoWord(growResult), 
  358.                                     HiWord(growResult), TRUE);
  359.                             EraseRect (&whichWindow->portRect);
  360.                             DrawGrowIcon (whichWindow);
  361.                             break;
  362.                         case inGoAway:
  363.                             track = TrackGoAway (whichWindow, myEvent.where);
  364.                             if (track)
  365.                                 CloseWindow (whichWindow);
  366.                             break;
  367.                         case inZoomIn:
  368.                             track = TrackBox (whichWindow, myEvent.where, inZoomIn);
  369.                             if (track) {
  370.                                 ZoomWindow (whichWindow, inZoomIn, TRUE);
  371.                                 EraseRect (&whichWindow->portRect);
  372.                                 DrawGrowIcon (whichWindow);
  373.                                 }
  374.                             break;
  375.                         case inZoomOut:
  376.                             track = TrackBox (whichWindow, myEvent.where, inZoomOut);
  377.                             if (track) {
  378.                                 ZoomWindow (whichWindow, inZoomOut, TRUE);
  379.                                 EraseRect (&whichWindow->portRect);
  380.                                 DrawGrowIcon (whichWindow);
  381.                                 }
  382.                             break;
  383.                         default:
  384.                             break;
  385.                         }
  386.                     break;
  387.                 case keyDown:
  388.                     break;
  389.                 case autoKey:
  390.                     break;
  391.                 case updateEvt:
  392.                     if ((WindowPtr) myEvent.message == myWindow) {
  393.                         BeginUpdate((WindowPtr) myWindow);
  394.                         EndUpdate((WindowPtr) myWindow);
  395.                         }
  396.                     break;
  397.                 case diskEvt:
  398.                     break;
  399.                 case activateEvt:
  400.                     break;
  401.                 case 15:
  402.                     if ((myEvent.message << 31) == 0) { /* Suspend */
  403.                         yieldTime = 30;
  404.                         HideWindow((WindowPtr) myWindow);
  405.                         }
  406.                     else { /* Resume */
  407.                         yieldTime = 0;
  408.                         ShowWindow((WindowPtr) myWindow);
  409.                         SetPort((WindowPtr) myWindow);
  410.                         }
  411.                     break;
  412.                 default:
  413.                     break;
  414.                 }
  415.             }
  416.         }
  417. }